var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../utils/tools/index"),
  s = require("../../../config/index"),
  u = require("../../../components/base/m-button/index"),
  d = e(require("./behavior"));

function o(e) {
  return c.apply(this, arguments)
}

function c() {
  return (c = n(r().mark((function e(t) {
    var n, a, s, u, d, o, c, l, m, p, h, f, _, v, b, g, y, q, x, T, w, k, C, V, X;
    return r().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 2, $.request["GET/business/engineering/approval/user/detail/".concat(t)]();
        case 2:
          n = e.sent, a = i(n, 1), 20002 === (s = a[0]).code && (console.log(s), u = s.data, d = u.desc, o = u.manufacture_date, c = u.title, l = u.use_type, m = u.worked_hour, p = u.sold_price, h = u.rent_price, f = u.brand_id, _ = u.model_id, v = u.class_id, b = u.address, g = u.province_id, y = u.city_id, q = u.latitude, x = u.longitude, T = u.sold_unit, w = u.rent_unit, k = u.image_arr, C = u.status, V = {
            address: b,
            city_id: y,
            latitude: q,
            longitude: x,
            province_id: g
          }, this.selectComponent("#form").setValues({
            approvalUserName: u.approvalUserName,
            approvalUserPhone: u.approvalUserPhone,
          }), this.setData({


          }));
        case 6:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}

function l(e, t) {
  return m.apply(this, arguments)
}

function m() {
  return (m = n(r().mark((function e(n, s) {
    var u, d, o, c, l;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return u = a.common.compactObj(n), d = s ? "POST/business/engineering/approval/user/edit/" + n.uu : "POST/business/engineering/approval/user/add", e.next = 4, u.cityText = u.city_text, u.cityId = u.city_id, u.provinceId = u.province_id, u.provinceText = u.province_text, $.request[d](t({}, u), {
            "content-type": "application/json"
          });
        case 4:
          o = e.sent, c = i(o, 1), l = c[0], 20002 == l.code ? ($.msg("添加成功"), setTimeout((function () {
            $.router.back({
              params: {
                "page-type": "publish"
              }
            })
          }), 2e3)) : $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: l.msg,
            cancelText: "知道了",
            confirmText: ""
          });
        case 9:
        case "end":
          return e.stop()
      }
    }), e)
  })))).apply(this, arguments)
}
Page({
  behaviors: [d.default],
  data: {
    mode: s.typeMode.device,
    recommendList: [],
    machineValue: null,
    useTypeList: [{
      id: 1,
      name: "出租"
    }, {
      id: 2,
      name: "出售"
    }, {
      id: 3,
      name: "出租/出售"
    }],
    useTypeValue: {
      id: 1,
      name: "出租"
    },
    date: '请选择日期',
    statusList: [{
      id: 1,
      name: "空闲中"
    }, {
      id: 2,
      name: "工作中"
    }],
    title: "",
    btn_txt: "立即添加",
    uu_id: "",
    engineeringId: ""
  },
  bindDateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },

  onLoad: function (e) {
    if (e.id) {
      this.setData({
        engineeringId: e.id
      })
    }
    if (e.uu_id) {
      this.setData({
        uu_id: e.uu_id,
        title: '修改审核员',
        btn_txt: "立即修改"
      })
    } else {
      this.setData({
        uu_id: e.uu_id,
        title: '添加联系人',
        btn_txt: "立即添加"
      })
    }

    o.call(this, e.uu_id)
  },
  onSubmit: (0, u.apply)(n(r().mark((function e() {
    var i, n, a, s, u, d, o, c, m, p, h, f, _, v;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return a = this.data, s = a.uu_id, u = a.mode, d = a.useTypeValue, e.next = 6, this.selectComponent("#form").verify({
            approvalUserName: [{
              required: !0,
              message: "请填写姓名"
            }],
            approvalUserPhone: [{
              required: !0,
              message: "请填写手机号"
            }]
          });
        case 6:
          if (o = e.sent, null != d && d.id) {
            e.next = 11;
            break
          }
          return e.abrupt("return", void $.msg("请选择机械用途"));
        case 9:
          if (o.detail && !((null === (i = o.detail) || void 0 === i ? void 0 : i.length) < 5)) {
            e.next = 11;
            break
          }
          return e.abrupt("return", void $.msg("设备简介必须大于5个字符"));
        case 11:
          c = o.address, m = o.machine, p = o.brand, h = o.model, f = o.images, _ = o.status, v = t(t({
            approvalUserPhone: o.approvalUserPhone || "",
            approvalUserName: o.approvalUserName || "",
            engineeringId: this.data.engineeringId
          }, c), {}, {

          }), s && (v.uu = s), l.call(this, v, s);
        case 13:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  onClickUseType: function (e) {
    var t = e.target.dataset.item;
    this.setData({
      useTypeValue: {
        id: t.id,
        name: t.name
      }
    })
  }
});